import { AppModel } from '../../models/app.js'
const ModelApp = new AppModel()
const App = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    visible: Boolean,
    redid:String
  },
  methods: {
    // 关闭closeNewRed
    closeNewRed() {
      this.setData({
        visible: false
      })
    },
    // 领红包
    newRedToUser() {
      ModelApp.newUserRed({ redId: this.properties.redid })
        .then(res => {
          this.setData({
            visible: false
          })
          App.WxService.showToast({
            title: `恭喜你成功领取${res.data.gold}金币`,
            icon: 'none'
          })
          // 更新数据
          setTimeout(() => {
            ModelApp._getVipInfo().then(res => {
              App.globalData.userInfo = res.data.userInfo
            })
          }, 2000)
        })
        .catch(err => {
           this.setData({
            visible: false
          })
        })
    },
    triggerUserRed() {
      // 获取新手红包
      this.triggerEvent('homeRed')
    }
  }
})
